<?php
namespace App\Models;

/**
 * 系统公告对象
 */
class MNotices extends BaseModel
{
    public $table = "notices";

    //表关系区===========================================================================


    //数据验证区===========================================================================

    /**
     * 信息存储验证
     * $flag 0 = rules  1 = msg
     */
    public static function editRulesWithMsg($flag)
    {
        $rules = array(
            "title"   => "required|max:100",
            'content' => 'required',
            'start'   => 'required',
            'end'     => 'required',
        );

        $msg = array(
            "start.required" => "公告开始时间必须填写！",
            "end.required"   => "公告结束时间必须填写！"
        );

        if ($flag == 0) {
            return $rules;
        } else {
            return $msg;
        }
    }

    //数据逻辑区===========================================================================

    /**
     * 保存或更新
     */
    public function saveData($title, $content, $start, $end)
    {
        $this->title = $title;
        $this->content = $content;
        $this->start = $start;
        $this->end = $end;
        $this->time = time();

        return $this->save();
    }

    /**
     *更新已阅读量
     */
    public function incRead()
    {
        $this->read += 1;
        return $this->save();
    }
}